package agendaSystem;

import static org.junit.Assert.*;

import org.junit.BeforeClass;
import org.junit.Test;

public class EntryTests {
	
	private static Event tester;
	private static Meeting tester2;
	private static PersonalEntry tester3, tester4, tester5;
	private static Agenda agenda1,agenda2;
	
	/**
	 * Set up a mutable test fixture.
	 * 
	 * @post	The variable tester references a new Event with a correct description
	 * 			on day 12 for agenda1.
	 * @post	The variable tester2 references a new Meeting with a correct description
	 * 			on day 22 that occupies slot 13, 14 and 15 for agenda 1 and agenda2.
	 * @post	The variable tester3 references a new PersonalEntry with a correct description
	 * 			on day 80 that occupies slot 6, 8, 15, 21 and 22 for agenda1.
	 * @post	The variable tester4 references a new PersonalEntry with a correct description
	 * 			on day 80 that occupies slot 16, 20 and 23 for agenda1.
	 * @post	The variable tester4 references a new PersonalEntry with a correct description
	 * 			on day 80 that occupies slot 14 for agenda1.
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		agenda1 = new Agenda("Bob");
		agenda2 = new Agenda("Alice");
		Agenda[] meeters = {agenda1};
		Agenda[] meeters1 = {agenda1, agenda2};
		tester = new Event("Test", 12, agenda1);
		tester2 = new Meeting(meeters1,"Test2",22,13,14,15);
		tester3 = new PersonalEntry(meeters, "Test3", 80, 6,8,15,21,22);
		tester4 = new PersonalEntry(meeters, "Test4", 80, 16,20,23);
		tester5 = new PersonalEntry(meeters, "Test5", 80, 14);
	}
	
	@Test
	public final void Constructor_Event() {
		assertEquals("Test", tester.getDescription());
		assertEquals(12, tester.getDay());
		assertFalse(tester.getSlots()[0]);
		assertFalse(tester.getSlots()[16]);
		assertFalse(tester.getSlots()[22]);
	}
	
	@Test
	public final void Constructor_Meeting() {
		assertEquals("Test2", tester2.getDescription());
		assertEquals(22, tester2.getDay());
		assertTrue(tester2.getSlots()[12]);
		assertTrue(tester2.getSlots()[13]);
		assertTrue(tester2.getSlots()[14]);
		assertFalse(tester2.getSlots()[6]);
		assertFalse(tester2.getSlots()[22]);
	}
	
	@Test
	public final void Constructor_PersonalEntry() {
		assertEquals("Test3", tester3.getDescription());
		assertEquals(80, tester3.getDay());
		assertTrue(tester3.getSlots()[5]);
		assertTrue(tester3.getSlots()[14]);
		assertTrue(tester3.getSlots()[21]);
		assertFalse(tester3.getSlots()[6]);
		assertFalse(tester3.getSlots()[17]);
	}
	
	@Test
	public final void isValidSLot_TrueCase() {
		assertTrue(tester3.isValidSlot(5));
	}
	
	@Test
	public final void isValidSLot_FalseCase() {
		assertFalse(tester2.isValidSlot(31));
	}
	
	@Test
	public final void addSlot_SingleCase() {
		tester2.addSlot(16);
		assertTrue(tester2.getSlots()[15]);
	}
	
	@Test
	public final void removeSlot_SingleCase() {
		tester3.removeSlot(22);
		assertFalse(tester3.getSlots()[21]);
	}
	
	@Test
	public final void getFirstSlot_SingleCase_Meeting() {
		assertEquals(13, tester2.getFirstSlot());
	}
	
	@Test
	public final void getFirstSlot_SingleCase_Event() {
		assertEquals(1, tester.getFirstSlot());
	}
	
	@Test
	public final void getLastSlot_SingleCase_Meeting() {
		assertEquals(15, tester2.getLastSlot());
	}
	
	@Test
	public final void getLastSlot_SingleCase_Event() {
		assertEquals(24, tester.getLastSlot());
	}
	
	@Test
	public final void getNbSlots_SingleCase_Meeting() {
		assertEquals(3, tester2.getNbSlots());
	}
	
	@Test
	public final void getNbSlots_SingleCase_Event() {
		assertEquals(24, tester.getNbSlots());
	}

	@Test
	public final void startsBefore_TrueCase() {
		assertTrue(tester5.startsBefore(tester4));
	}
	
	@Test
	public final void startsBefore_FalseCase() {
		assertFalse(tester4.startsBefore(tester3));
	}
	
	@Test
	public final void moveNbSlots_SingleCase() {
		tester5.moveNbSlots(3);
		assertTrue(tester5.getSlots()[16]); 
	}
}
